<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<include file="public:meta" />
	<link href="../public/css/personal/common.css" rel="stylesheet" type="text/css" />
	<link href="../public/css/personal/personal_user.css" rel="stylesheet" type="text/css" />
	<link href="../public/css/personal/personal_ajax_dialog.css" rel="stylesheet" type="text/css" />
	<script src="../public/js/personal/jquery.common.js" type="text/javascript" language="javascript"></script>
</head>
<body>
	<include file="Personal:index_header" />
	<div class="user_main">
		<include file="Personal:index_left_nav" />
  	  	<div class="mainbox">
			<!--切换卡 -->
			<div class="tab">
				<a class="li J_hoverbut" href="{:U('index')}">我的{:C('qscms_points_byname')}</a>
				<a class="li J_hoverbut " href="{:U('task')}" >我的任务</a>
				<a class="li select " href="{:U('increment')}">增值服务</a>
				<a class="li J_hoverbut " href="{:U('order_list')}">服务订单</a>
				<notempty name="apply['Mall']">
					<a class="li J_hoverbut " href="{:U('order_list_goods')}">商城订单</a>
				</notempty>
			  	<div class="clear"></div>
			</div>

			<!--切换卡结束 -->
			<div class="order_add">
		    <form target="_blank" id="cash_pay_form" method="post" action="{:U('increment_add_save')}">
			  <div class="lefttit">服务名称：</div>
			  <div class="rights">
			    <div class="sname font_blue">简历置顶</div>
			  </div>
			  <div class="lefttit">选择简历：</div>
			  <div class="rights">
			  <if condition="$resume">
			   <div class="input_245_34_div selectinput J_hoverinput J_dropdown J_listitme_parent">
					<span class="J_listitme_text">选择简历</span>
					<div class="dropdowbox12 J_dropdown_menu">
			            <div class="dropdow_inner12">
			                <ul class="nav_box">
			                	<volist name="resume" id="resume">
			                		<li><a class="J_listitme" href="javascript:;" data-code="{$resume['id']}" buy="{$resume['stick']}">{$resume['title']}</a></li>
								</volist>
			                </ul>
			            </div>
			        </div>
					<input class="J_listitme_code" name="resume_id" id="resume_id" type="hidden" value="" />
					<input name="buy" id="buy" type="hidden" value="0" />
				</div>
				<else />
				<div class="input_245_34_div selectinput J_hoverinput J_dropdown J_listitme_parent">
					<span class="J_listitme_text">没有可以置顶的简历</span>
					<input class="J_listitme_code" name="resume_id" id="resume_id" type="hidden" value="" />
					<input name="buy" id="buy" type="hidden" value="0" />
				</div>
				</if>
			  </div>
			  <div class="lefttit">选择时长：</div>			  
			  <div class="rights">
			  	<volist name="choose_arr" id="vo">
				<div class="duration J_hoverbut <if condition="$key eq 0">select</if>" days="{$vo['days']}" points="{$vo['points']}">
				  <div class="dl">{$vo['days']} 天</div>
				  <div class="dr">{$vo['points']}{:C('qscms_points_byname')}</div>
				</div>
				</volist>
				<div class="clear"></div>
			  </div>
			  
				<input type="hidden" id="points" name="points" value="{$choose_arr[0]['points']}">
				<input type="hidden" id="mypoints" value="{$mypoints}">
			   <div class="lefttit">支付方式：</div>
			  <div class="rights">
				   <div class="pay_select">
						 <!--小标题切换卡 -->
						<div class="thtab">
							<div class="li J_hoverbut select points_tab" >{:C('qscms_points_byname')}兑换</div>
							<div class="li J_hoverbut cash_tab"  >现金支付</div>
							<div class="clear"></div>
						</div>
				   </div>
			  </div>
			  <div class="clear"></div>
			  
			<!--积分支付 -->
			<div class="tabshow" id="points_wrap" style="display:block">
				<div class="enough">
					<div class="lefttit">所需{:C('qscms_points_byname')}：</div>
				  	<div class="rights">
				    	<div class="count link_blue"> 
					  		<strong class="need_points"></strong>{:C('qscms_points_byname')}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前拥有 <span>{$mypoints}</span> {:C('qscms_points_byname')}，<a href="{:U('task')}">做任务</a> 还可以获得更多{:C('qscms_points_byname')}哦！		
					  	</div>
			 	  	</div>
				  	<div class="clear"></div>
				  	<div class="lefttit">&nbsp;</div>
				  	<div class="rights">
				     	<input name="" type="button" id="points_pay_submit" class="btn_yellow J_hoverbut btn_100_38" value="立即兑换" />
				  	</div>
				</div>
			  	<div class="notenough" style="display:none">
			  		<div class="lefttit">所需{:C('qscms_points_byname')}：</div>
				  	<div class="rights">
				    	<div class="count link_blue"> 
							<strong class="need_points"></strong>{:C('qscms_points_byname')}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当前拥有 <span>{$mypoints}</span> {:C('qscms_points_byname')}，不足以兑换此项服务，建议您 <a href="{:U('task')}">做任务</a> 获得更多{:C('qscms_points_byname')}！
						</div>
		 	  		</div>
				  	<div class="clear"></div>
				  	<div class="lefttit">&nbsp;</div>
				  	<div class="rights">
				    	<input name="" type="button" class="btn_yellow J_hoverbut btn_100_38 btn_disabled" value="立即兑换" />
				 	</div>
			  	</div>
			  	<div class="clear"></div>
			</div>
			  
		    <div class="tabshow" id="cash_wrap">
				<div class="lefttit">&nbsp;</div>
			  	<div class="rights">
					<!--默认是不做任何选择 没有select -->
					<volist name="payment" id="vo">
					<div typename="{$vo['typename']}" class="pays J_hoverbut"><img src="../public/images/pay_{$vo['typename']}.png"   border="0"/>
						<div class="hook"></div>
					</div>
					</volist>
					<!-- <div class="pays J_hoverbut">
						<img src="../public/images/pay_weixn.png" border="0"/>
						<div class="hook"></div>
					</div> -->
					<div class="clear"></div>	
			  	</div>
				<div class="lefttit">订单价格：</div>
				<div class="rights">
				    <div class="price"><strong id="need_cash"></strong>元</div>
				    <div>
						<label><input id="J_integralforcash" type="checkbox" checked="checked" /> 使用{:C('qscms_points_byname')}抵现</label><span class="small">（当前拥有<span class="orange">{$mypoints}</span>{:C('qscms_points_byname')}）</span><input name="" type="text" class="input_110_34" id="J_integralforcash_input" onkeyup="if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))" value=""><span class="small"> {:C('qscms_points_byname')}</span> <span class="orange">&nbsp;&nbsp;-<span id="J_integralforcashvalue">0</span></span> 元
					</div>
				</div>
				<div class="lefttit">应付金额：</div>
				<div class="rights">
				    <div class="price"><strong id="pay_cash"></strong>元</div>
				</div>
				<input type="hidden" id="amount" name="amount" value="">
				<input type="hidden" name="payment_name" id="payment_name" value="">
				<input type="hidden" name="days" id="days" value="{$choose_arr[0]['days']}">
				<input type="hidden" name="pay_type" value="cash">
				<input type="hidden" name="type" value="stick">
				<input type="hidden" name="is_deductible" id="is_deductible" value="1"><!-- 是否选中使用积分抵现 -->
				<input type="hidden" name="deductible" id="deductible" value=""><!-- 抵现积分 -->
				<div class="lefttit">&nbsp;</div>
				<div class="rights">
					<input name="" type="button" id="cash_pay_submit" class="btn_yellow J_hoverbut btn_100_38" value="立即支付" />
				</div>
		    </div>
		</div>
		</form>
		</div>
				<div class="clear"></div>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<include file="Personal:index_footer" />
	<script type="text/javascript">
		$(document).ready(function(){
			$(".J_listitme").click(function(){
				$("#buy").val($(this).attr('buy'));
			});
			 function select_pay_type(no_change_tab){
				var mypoints = parseInt($("#mypoints").val());
				var current_points = parseInt($("#points").val());
				if(mypoints<current_points){
					if(no_change_tab==0){
						$(".pay_select .li").removeClass('select');
						$(".cash_tab").addClass('select');
						$("#points_wrap").hide();
						$("#cash_wrap").show();
					}
					$('#J_integralforcash_input').val(mypoints);
					$('#deductible').val(mypoints);
					$(".enough").hide();
					$(".notenough").show();
				}else{
					if(no_change_tab==0){
						$(".pay_select .li").removeClass('select');
						$(".points_tab").addClass('select');
						$("#cash_wrap").hide();
						$("#points_wrap").show();
					}
					$('#J_integralforcash_input').val(current_points);
					$('#deductible').val(current_points);
					$(".enough").show();
					$(".notenough").hide();
				}
				$(".need_points").html(current_points);
				var need_cash = current_points/parseInt("{$payment_rate}");
				$("#need_cash").html(need_cash.toFixed(2));
				$("#amount").val(need_cash.toFixed(2));
				$('#J_integralforcashvalue').text(($('#J_integralforcash_input').val()/parseInt("{$payment_rate}")).toFixed(2));
				if ($('#J_integralforcash').is(':checked')) {
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
				} else {
					$("#pay_cash").html(need_cash.toFixed(2));
					$('#amount').val(need_cash.toFixed(2));
				}
			}
			select_pay_type(0);
			$(".duration").click(function(){
				$(this).siblings().removeClass('select');
				$(this).addClass('select');
				$("#days").val($(this).attr('days'));
				$("#points").val($(this).attr('points'));
				select_pay_type(1);
			});
			$('#J_integralforcash_input').keyup(function() {
				var mypoints = parseInt($("#mypoints").val());
				var current_points = parseInt($("#points").val());
				var minpointsValue = mypoints >= current_points ? current_points : mypoints;
				var thisvalue = $(this).val();
				if (thisvalue > minpointsValue) {
					$('#J_integralforcash_input').val(minpointsValue);
				};
				$('#J_integralforcashvalue').text(($('#J_integralforcash_input').val()/parseInt("{$payment_rate}")).toFixed(2));
				$('#deductible').val($('#J_integralforcash_input').val());
				if($('#J_integralforcash').is(':checked')){
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
				}
			});
			$('#J_integralforcash').click(function() {
				if ($('#J_integralforcash').is(':checked')) {
					$("#pay_cash").text((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#amount').val((parseFloat($('#need_cash').text())-parseFloat($('#J_integralforcashvalue').text())).toFixed(2));
					$('#is_deductible').val('1');
				} else {
					$("#pay_cash").html(parseFloat($('#need_cash').text()).toFixed(2));
					$('#amount').val(parseFloat($('#need_cash').text()).toFixed(2));
					$('#is_deductible').val('0');
				}
			});
			
			$("#points_pay_submit").click(function(){
				if(parseInt($("#buy").val())!=0){
					disapperTooltip("remind","该简历已置顶，不能重复购买，请重新选择简历！");
					return false;
				}
				ajax_pay('stick','points');
			});
			$(".pays").click(function(){
				$(this).siblings().removeClass('select');
				$(this).addClass('select');
				$("#payment_name").val($(this).attr("typename"));
			});
			$("#cash_pay_submit").click(function(){

				if(!$("#resume_id").val()){
					disapperTooltip("remind","请选择简历！");
					return false;
				}
				if(!$("#payment_name").val()){
					disapperTooltip("remind","请选择支付方式！");
					return false;
				}
				if(parseInt($("#buy").val())!=0){
					disapperTooltip("remind","该简历已置顶，不能重复购买，请重新选择简历！");
					return false;
				}
				if(parseFloat($("#amount").val())==0.00){
					ajax_pay('stick','points');
				}else{
					if($("#payment_name").val()=='wxpay'){
						var qsDialog = $(this).dialog({
			        		title: '微信支付',
							loading: true,
							showFooter: false
						});
						$.ajax({
			                cache: true,
			                type: "POST",
			                url:"{:U('increment_add_save')}",
			                data:$('#cash_pay_form').serialize(),
			                dataType:"json",
			                success: function(result) {
			                    if(result.status==1){
			                    	qsDialog.setContent("<img src='"+result.data+"' alt='扫描二维码' width='250' height='250' />");
									window.setInterval(run, 5000);
			                    }else{
			                    	qsDialog.setContent('<div class="confirm">' + result.msg + '</div>');
									return false;
			                    }
			                }
			            });
					}else{
						var url = "{:U('PersonalService/confirm_pay_status')}";
						var qsDialog=$(this).dialog({
							title: '确认支付',
							loading: true,
							border: false,
							yes: function() {
								window.location.href="{:U('Personal/resume_list')}";
							},
							cancel:function(){
								window.location.href="{:U('PersonalService/order_list')}";
							}
						});
						$.getJSON(url,function(result){
			        		if(result.status == 1){
			        			qsDialog.setContent(result.data.html);
			        			qsDialog.setBtns(['支付完成', '遇到问题']);
			        		}else{
			        			disapperTooltip('remind',result.msg);
			        		}
			        	});
						$("#cash_pay_form").submit();
					}
				}
			});

		});
		
        function run(){
            $.getJSON("{:U('check_weixinpay_notify')}",function(result){
                if(result.status==1){
                   location.href=result.data;
                }
            });
        }
        function ajax_pay(type,pay_type){
			var days = $("#days").val();
			var resume_id = $("#resume_id").val();
			var payment_name = "points";
			$.post("{:U('increment_add_save')}",{pay_type:pay_type,type:type,days:days,resume_id:resume_id,payment_name:payment_name},function(result){
				if(result.status==1){
					disapperTooltip("success", "兑换成功！");
					setTimeout(function () {
                        location.href='{:U("Personal/resume_list")}';
                    }, 2000);
				}else{
					disapperTooltip("remind", result.msg);
					return false;
				}
			},'json');
        }
	</script>
</body>
</html>